function hugotest(output, type, varargin)
%HUGOTEST(OUTPUT, TYPE, ...)
% run various tests on hugo boss.
% The following values must be at the first of varargin.
% Usage        |    Description
% "-noextract" | Skip extract features, instead load it from OUTPUT.
% "-method"    | Set method in train & test.
%    lda, svm, svm_rbf, ensemble, _svm, _svm_rbf
% note:
%    _svm & _svm_rbf calls libsvm within matlab and makes MATLAB not
%    respond to any inputs, including (CTRL+C). So it is recommended to use
%    svm & svm_rbf instead, which exec libsvm binaries.
% "-stegopath" | Specify path to stego images.
% "-coverpath" | Specify path to cover images.
%

% default settings
extract = 1;
coverpath = '/media/win_d/HUGOBOSS/0.92/cover/*.pgm';
stegopath = '/media/win_d/HUGOBOSS/0.92/stego/*.pgm';
svmtrainpath = 'svm-train';
svmpredictpath = 'svm-predict';

% parse inputs
nvarargin = length(varargin);
start = 1;
method = 'all';
if nvarargin > 0
    while start <= nvarargin
        switch lower(varargin{start})
            case '-noextract'
                extract = 0;
                start = start + 1;
            case '-stegopath'
                stegopath = varargin{start+1};
                start = start + 2;
            case '-coverpath'
                coverpath = varargin{start+1};
                start = start + 2;
            case '-method'
                method = varargin{start+1};
                start = start + 2;
            otherwise
                break;
        end
    end
end

if extract
    disp('Extract features :');
    c = cell(1, 2);
    c{1} = coverpath;
    c{2} = stegopath;
    [results, param] = features2(c, type, varargin{start:nvarargin});
    cover = results{1};
    stego = results{2};
    clear results;
    save(output, 'cover', 'stego', 'param');
    clear param
end

% already extracted
load(output, 'cover', 'stego');

disp('Train and Test');
tmp = load(output, 'test_result');
if isfield(tmp, 'test_result')
    test_result = tmp.test_result;
    clear tmp;
else
    test_result = struct();
end
disp(method);
switch lower(method)
    case 'none'
    case 'all'
        test_result.lda = ldatest(stego, cover, 8074, 1000, 12);
        s1 = struct('verbose', 1, 'c', 4096, 'g', 8, 'kerneltype', 0, ...
            'svmtrain', svmtrainpath, 'svmpredict', svmpredictpath);
        test_result.svm = trainModel_libsvm3(stego, cover, 17000, 3000, 12, s1);
        test_result.ensemble = ensemble_test(stego, cover, 0, 0.888, 12, 3, 1);
    case 'lda'
        test_result.lda = ldatest(stego, cover, 8074, 1000, 12);
    case 'svm'
        s = struct('verbose', 1, 'c', 4096, 'g', 8, 'kerneltype', 0, ...
            'svmtrain', svmtrainpath, 'svmpredict', svmpredictpath);
        test_result.svm = trainModel_libsvm3(stego, cover, 17000, 3000, 12, s);
    case '_svm'
        test_result.svm = trainModel_libsvm2(stego, cover, 17000, 3000, 12, 1, 4096, 8);
    case 'svm_rbf'
        s = struct('verbose', 1, 'c', 4096, 'g', 8, 'kerneltype', 2, ...
            'svmtrain', svmtrainpath, 'svmpredict', svmpredictpath);
        test_result.svm_rbf = trainModel_libsvm3(stego, cover, 17000, 3000, 12, s);
    case '_svm_rbf'
        test_result.svm_rbf = trainModel_libsvm2(stego, cover, 17000, 3000, 12, 1, 4096, 8);
    case 'ensemble'
        test_result.ensemble = ensemble_test(stego, cover, 0, 0.888, 12, 3, 1);
    otherwise
        warning('unknown training / testing method');
end
save(output, '-append', 'test_result');

end
